package searching;

public class BinarySearch {

	public static final int NOT_FOUND = -1;

	public int search_1(int[] intArray, int key) {

		int lo = 0;
		int hi = intArray.length-1;

		while (lo <= hi) {
			int mid = lo + (hi - lo) / 2;
			if (key < intArray[mid]) {
				hi = mid - 1;
			} else if (key > intArray[mid]) {
				lo = mid + 1;
			} else {
				return mid;
			}
		}

		return NOT_FOUND;
	}
}
